/**
 * 路由的声明
 */
const router = require("koa-router")();
const userController = require("../controller/user");
const addCartController = require("../controller/addCart");
const goodsController = require("../controller/goodsData");
const favController = require("../controller/favorites");
const fileUploadController = require("../controller/fileUpload");
const addressController = require("../controller/address")

const {
  upload
} = require("../utils/upload");

/**
 * 首页模块
 */

/**
 * 用户模块
 */
router
  .post("/api/users/login", userController.login)
  .post('/api/users/register', userController.register);

/**
 * 商品
 */
router
  .post("/api/data/goodsData", goodsController.goodsData)
  .post("/api/data/getGoods", goodsController.getGoodsData)
  .get("/api/data/getAllGoods", goodsController.getGoodsAllData)

/**
 * 购物车
 */
router
  .post('/api/carts/addCart', addCartController.addCart)
  .post('/api/carts/getCart', addCartController.getCart)
  .post('/api/carts/deleteCart', addCartController.deleteCart)

/**
 * 收藏夹
 */
router
  .post("/api/data/addFav", favController.addFav)
  .post("/api/data/delFav", favController.delFav) 
  .post("/api/data/getFav", favController.getFav)
  .post("/api/data/getUserFav", favController.getUserFav)
  
  /**
 * 文件上传
 */
   router
   .post("/api/user/addAdd", addressController.addAdd)
   .post("/api/user/getAdd", addressController.getAdd)
   .post("/api/user/newAdd", addressController.newAdd)
  /**
 * 文件上传
 */
router.post(
  "/api/img/upload",
  upload.single("avatar"),
  fileUploadController.upload
);

module.exports = router;